﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OA.DBUtility;
using OA.Model;

namespace OA.Manager
{
    public class EmployeeTrainingMappingManager
    {
        private SqlService<EmployeeTrainingMappingInfo> _sqlService = null;

        public EmployeeTrainingMappingManager()
        {
            _sqlService = new SqlService<EmployeeTrainingMappingInfo>();
        }

        #region  Method


        /// <summary>
        /// 插入员工培训详情
        /// </summary>
        /// <param name="employeeTraining"></param>
        /// <returns></returns>
        public bool InsertEmployeeTrainingMappingInfo(EmployeeTrainingMappingInfo employeeTraining)
        {
            if (employeeTraining == null) throw new ArgumentNullException("employeeTraining");
            return _sqlService.SaveEntity(employeeTraining);
        }

        /// <summary>
        ///根据条件得到员工培训明细
        /// </summary>
        ///<returns></returns>
        public EmployeeTrainingMappingInfo GetEmployeeTrainingMappingInfo(string filter)
        {
            string sql = "SELECT * FROM dbo.EmployeeTrainingMapping WHERE 1=1 AND " + filter;
            return _sqlService.GetSingleBySqlString(sql);
        }

        /// <summary>
        /// 判断该培训是否存在
        /// </summary>
        /// <param name="filter"> </param>
        /// <returns></returns>
        public bool IsEmployeeTrainingMappingInfo(string filter)
        {
            object value = _sqlService.ExecuteScalar("SELECT * FROM dbo.EmployeeTrainingMapping WHERE 1=1 AND" + filter);
            if (value != null)
            {
                int count;
                if (int.TryParse(value.ToString(), out count) && count > 0)
                {
                    return true;
                }
            }
            return false;
        }

        /// <summary>
        /// 根据指定的字段更新，字段名是数据库中对应的名称
        /// </summary>
        /// <param name="employeeTrainingMapping"> </param>
        /// <param name="needUpdateFields"></param>
        /// <returns></returns>
        public bool UpdateEmployeeTrainingMappingInfo(EmployeeTrainingMappingInfo employeeTrainingMapping, List<string> needUpdateFields, string filter)
        {
            return _sqlService.UpdateByFieldsFilter(employeeTrainingMapping, needUpdateFields, filter);
        }

        /// <summary>
        /// 删除培训详情
        /// </summary>
        /// <param name="filter"> </param>
        /// <returns></returns>
        public bool DeleteEmployeeTrainingMappingInfo(string filter)
        {
            return _sqlService.DeleteEntity("EmployeeTrainingMapping",filter);
        }
        #endregion  Method
    }
}
